package com.cqeec.view;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;

import com.cqeec.domain.Ieaved;
import com.cqeec.service.CallRollService;
import com.cqeec.service.imp.CallRollServiceImpl;
import com.cqeec.utils.JDBCUtils;

import javax.swing.JEditorPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.awt.event.ActionEvent;
/**
 *  请假界面
 * @author 邓学强
 *
 */
public class Leaved extends JInternalFrame {
	private JTextField studentNumTxt;
	private JTextField courseName;
	private JTextField timeTxt;
	private JEditorPane vacationCause;
	private JTextField textField;
	private Connection con=null;
	private JDBCUtils jdbcUtils=new JDBCUtils();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Leaved frame = new Leaved();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Leaved() {
		setIconifiable(true);
		setClosable(true);
		setTitle("请假");
		setBounds(100, 100, 848, 514);
		
		JLabel lblNewLabel = new JLabel("学号：");
		lblNewLabel.setFont(new Font("宋体", Font.BOLD, 20));
		
		studentNumTxt = new JTextField();
		studentNumTxt.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("请假课程：");
		lblNewLabel_1.setFont(new Font("宋体", Font.BOLD, 20));
		
		courseName = new JTextField();
		courseName.setColumns(10);
		
		JLabel label = new JLabel("请假原因：");
		label.setFont(new Font("宋体", Font.BOLD, 20));
		
		 vacationCause = new JEditorPane();
		
		JLabel label_1 = new JLabel("");
		
		JLabel label_2 = new JLabel("日期：");
		label_2.setFont(new Font("宋体", Font.BOLD, 20));
		
		timeTxt = new JTextField();
		timeTxt.setColumns(10);
		
		JButton button = new JButton("确定请假");
		button.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				/**
				 * 请假按钮事件
				 */
			String studentNum=studentNumTxt.getText();//获取学生学号
			String time=timeTxt.getText();//获取请假时间
			String courseNa=courseName.getText();//请假课程
			String  vacationause=vacationCause.getText();//获取请假内容
			String classes=textField.getText();//获取班级
			Ieaved ieaved=new Ieaved(courseNa, classes, time, vacationause, studentNum);
			if(studentNum.equals("")) {
				JOptionPane.showMessageDialog(null, "请输入你的学号", "提示", JOptionPane.ERROR_MESSAGE);
				studentNumTxt.requestFocus();
				return;
			}
			if(classes.equals("")) {
				JOptionPane.showMessageDialog(null, "请输入你的学号", "提示", JOptionPane.ERROR_MESSAGE);
				studentNumTxt.requestFocus();
				return;
			}
			
			if(time.equals("")) {
				JOptionPane.showMessageDialog(null, "请输入请假时间", "提示", JOptionPane.ERROR_MESSAGE);
				timeTxt.requestFocus();
				return;
			} 

			if(courseNa.equals("")) {
				JOptionPane.showMessageDialog(null, "请输入请假课程", "提示", JOptionPane.ERROR_MESSAGE);
				courseName.requestFocus();
				return;
			}

			if(vacationause.equals("")) {
				JOptionPane.showMessageDialog(null, "请输入请假理由", "提示", JOptionPane.ERROR_MESSAGE);
				vacationCause.requestFocus();
				return;
			}
			CallRollService callRollService=new CallRollServiceImpl();
			con=jdbcUtils.getConnection();
			callRollService.call_rolls(con,ieaved);
			
				
			}
		});
		button.setFont(new Font("宋体", Font.BOLD, 20));
		
		JButton button_1 = new JButton("重置");
		button_1.setFont(new Font("宋体", Font.BOLD, 20));
		
		textField = new JTextField();
		textField.setColumns(10);
		
		JLabel label_3 = new JLabel("班级：");
		label_3.setFont(new Font("宋体", Font.BOLD, 20));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(38)
							.addComponent(lblNewLabel_1))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(59)
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
								.addComponent(label_3)
								.addComponent(lblNewLabel))))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(button)
							.addGap(115)
							.addComponent(button_1)
							.addGap(338))
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
								.addComponent(textField, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
								.addComponent(courseName, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 189, GroupLayout.PREFERRED_SIZE)
								.addComponent(studentNumTxt, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
								.addGroup(groupLayout.createSequentialGroup()
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addGroup(groupLayout.createSequentialGroup()
											.addGap(116)
											.addComponent(label_1))
										.addGroup(groupLayout.createSequentialGroup()
											.addGap(122)
											.addComponent(label_2)
											.addGap(6)
											.addComponent(timeTxt, GroupLayout.PREFERRED_SIZE, 134, GroupLayout.PREFERRED_SIZE)))
									.addContainerGap(158, Short.MAX_VALUE))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(4)
									.addComponent(label)
									.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(vacationCause, GroupLayout.PREFERRED_SIZE, 327, GroupLayout.PREFERRED_SIZE)
									.addGap(41))))))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(78)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(16)
									.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
										.addComponent(studentNumTxt, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
										.addComponent(lblNewLabel)
										.addComponent(label_2)))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(29)
									.addComponent(timeTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(29)
									.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
										.addComponent(textField, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
										.addComponent(label_3))
									.addGap(39)
									.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
										.addComponent(lblNewLabel_1)
										.addComponent(label)
										.addComponent(courseName, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(89)
									.addComponent(vacationCause, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE))))
						.addComponent(label_1))
					.addPreferredGap(ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(button)
						.addComponent(button_1))
					.addGap(53))
		);
		getContentPane().setLayout(groupLayout);

	}
}
